package com.example.bms.mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.bms.entity.MultiQuestion;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import java.util.List;


/**
 * @apiNote 选择题题库的增加和删除
 * @author
 * @email 3108289016@qq.com
 * @since 1.0.0
 */
//选择题
@Mapper
public interface MultiQuestionMapper {


    /**
     * @apiNote 查询选择题题库
     * @author
     * @param PaperId 试卷编号
     * @email 3108289016@qq.com
     * @return IPage<MultiQuestion>
     * @since 1.0.0
     */
    @Select("select * from multi_question where questionId in (select questionId from paper_manage where questionType = 1 and paperId = #{paperId})")
    List<MultiQuestion> findByIdAndType(Integer PaperId);


    /**
     * @apiNote 查询选择题题库
     * @author
     * @param page 页数
     * @email 3108289016@qq.com
     * @return IPage<MultiQuestion>
     * @since 1.0.0
     */
    @Select("select * from multi_question")
    IPage<MultiQuestion> findAll(Page page);


    /**
     * @apiNote 查询最后一条记录的questionId
     * @author
     * @email 3108289016@qq.com
     * @return MultiQuestion
     * @since 1.0.0
     */
    @Select("select questionId from multi_question order by questionId desc limit 1")
    MultiQuestion findOnlyQuestionId();


    /**
     * @apiNote 增加试题
     * @author
     * - subject 科目
     * - question 问题
     * -answerA 答案（A,B,C,D）
     * @email 3108289016@qq.com
     * @return int类型，插入成功返回1，插入失败返回0
     * @since 1.0.0
     */
    @Options(useGeneratedKeys = true,keyProperty = "questionId")
    @Insert("insert into multi_question(subject,question,answerA,answerB,answerC,answerD,rightAnswer,analysis,section,level) " +
            "values(#{subject},#{question},#{answerA},#{answerB},#{answerC},#{answerD},#{rightAnswer},#{analysis},#{section},#{level})")
    int add(MultiQuestion multiQuestion);


    /**
     * @apiNote 查询试卷ID
     * @author
     * - subject 科目
     * - question 问题
     * -answerA 答案（A,B,C,D）
     * @email 3108289016@qq.com
     * @return List<Integer>
     * @since 1.0.0
     */
    @Select("select questionId from multi_question  where subject =#{subject} order by rand() desc limit #{pageNo}")
    List<Integer> findBySubject(String subject,Integer pageNo);

}
